package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.mapper.AuthorsMapper;
import com.qf.mapper.BooksMapper;
import com.qf.mapper.CategoriesMapper;
import com.qf.pojo.Authors;
import com.qf.pojo.Books;
import com.qf.pojo.Categories;
import com.qf.service.IBooksService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BooksServiceImpl implements IBooksService {

    private BooksMapper booksMapper;
    private CategoriesMapper categoriesMapper;
    @Autowired
    public void setBooksMapper(BooksMapper booksMapper) {
        this.booksMapper = booksMapper;
    }
    @Autowired
    public void setCategoriesMapper(CategoriesMapper categoriesMapper) {
        this.categoriesMapper = categoriesMapper;
    }

    @Override
    public PageInfo<Books> findAll(int page,int limit) {
        PageHelper.startPage(page,limit);


        List<Books> booksList = booksMapper.findAll();
        System.out.println("书名"+booksList);
        for(Books books:booksList){
            Categories categoryname = categoriesMapper.findById(books.getCategoryid());
            books.setCategories(categoryname);
        }
        PageInfo pageInfo=new PageInfo(booksList);
        return pageInfo;
    }

    @Override
    public void addBooks(Books books) {
        booksMapper.addBooks(books);
    }
}
